using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;

namespace SharpMud.Text.Dynamic
{
    [XmlRoot("SimpleDynamicTextBody")]
    public class SimpleDynamicTextBody : ISimpleDynamicTextBody
    {
        private string _FileName;
        private SharpMud.DynamicTyping.AssembliedTypeLocation _CodeDomProvider;
        private string _Contents;

        public SimpleDynamicTextBody()
        {
            _FileName = "";
            _CodeDomProvider = new SharpMud.DynamicTyping.AssembliedTypeLocation();
            _CodeDomProvider.AssemblyLocation = "";
            _CodeDomProvider.FullTypeName = "";
            _Contents = "";
        }

        [XmlAttribute("ProviderAssembly")]
        public string CodeProviderAssembly
        {
            get
            {
                return _CodeDomProvider.AssemblyLocation;
            }
            set
            {
                _CodeDomProvider.AssemblyLocation = value;
            }
        }

        [XmlAttribute("ProviderType")]
        public string CodeProviderType
        {
            get
            {
                return _CodeDomProvider.FullTypeName;
            }
            set
            {
                _CodeDomProvider.FullTypeName = value;
            }
        }

        [XmlAttribute("FileName")]
        public string FileName
        {
            get
            {
                return _FileName;
            }
            set
            {
                _FileName = value;
            }
        }

        [XmlText()]
        public string Contents
        {
            get
            {
                return _Contents;
            }
            set
            {
                _Contents = value;
            }
        }

        #region ISimpleDynamicTextBody Members

        [XmlIgnore()]
        System.CodeDom.Compiler.CodeDomProvider ISimpleDynamicTextBody.CodeDomProvider
        {
            get
            {
                if (this.CodeProviderAssembly == "" && this.CodeProviderType == "")
                    return null;
                return (System.CodeDom.Compiler.CodeDomProvider)_CodeDomProvider.AcquireTypeInstance(); 
            }
        }

        [XmlIgnore()]
        string ISimpleDynamicTextBody.Contents
        {
            get { return _Contents; }
        }

        [XmlIgnore()]
        string ISimpleDynamicTextBody.FileName
        {
            get { return _FileName; }
        }

        #endregion
    }
}
